﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using BusinessComponents.Common;

namespace BusinessComponents
{
    [MetadataType(typeof(ReservationMasterMetadata))]
    public partial class ReservationMaster
    {

        public string UserName
        {
            get;set;
        }

        public string RoomList
        {
            get;set;
        }

        public string RoomTypeDesc
        {
            get;set;
        }

        public string StatusDesc
        {
            get
            {
                return IsCancelled == 0 ? "Confirmed" : "Cancelled";
            }

            set { }
        }

        public string TotalCostInDollar
        {
            get
            {
                return FinanceUtils.centToDollar(TotalCost);
            }

            set
            {
            }
        }

        public void populate()
        {
            UserName = this.Customer.UserName;
            RoomTypeDesc = this.RoomType.Description;

            if (this.ReservationDetails != null)
            {
                RoomList = "";
                HashSet<string> rms = new HashSet<string>();

                foreach (var r in this.ReservationDetails)
                {
                    rms.Add(r.RoomNo);
                }

                foreach (string rn in rms)
                {
                    RoomList += rn + ", ";
                }

                if (RoomList.Length >= 2)
                {
                    RoomList = RoomList.Substring(0, RoomList.Length - 2);
                }
            }
            else
            {
                RoomList = "N.A.";
            }
        }
    }

    public class ReservationMasterMetadata
    {
        [DisplayName("Applicant's Name")]
        public object UserName { get; set; }

        public object UserId{ get; set; }

        [DisplayName("Reservation ID")]
        public object ReservationId { get; set; }

        [Required]
        [DisplayName("Start Date")]
        [DataType(DataType.Date)]
        public object StartDate { get; set; }

        [Required]
        [DisplayName("End Date")]
        [DataType(DataType.Date)]
        public object EndDate { get; set; }

        [DisplayName("No. of Days")]
        public object DayCount { get; set; }

        [DisplayName("Room Type")]
        public object TypeCode { get; set; }

        [DisplayName("Room Type")]
        public object RoomTypeDesc { get; set; }

        [Required]
        [DisplayName("No. of Rooms")]
        public object RoomCount { get; set; }

        [DisplayName("Room(s) Allocated")]
        public object RoomList { get; set; }

        [Required]
        [DisplayName("No. of Pax")]
        public object NoOfPax { get; set; }

        [Required]
        [DisplayName("Total Cost")]
        public object TotalCost { get; set; }

        [DisplayName("Total Cost (S$)")]
        public string TotalCostInDollar { get; set; }

        [StringLength(256)]
        public object Remarks { get; set; }

        [DisplayName("Create Time")]
        public object CreatedDateTime { get; set; }

        [DisplayName("Reservation Status")]
        public object StatusDesc { get; set; }

        [DisplayName("Cancellation Time")]
        public object CancelDateTime { get; set; }
    }

    [MetadataType(typeof(ReservationDetailMetadata))]
    public partial class ReservationDetail
    {

    }

    public class ReservationDetailMetadata
    {
        [DisplayName("Room No.")]
        public object RoomNo { get; set; }

    }
}
